@echo off


if not exist "DATA.bin" (
	echo "NOT FOUND DATA.bin"
	goto EXIT
)

set CYGWIN_BIN=C:\cygwin\bin
%CYGWIN_BIN%\sha256sum DATA.bin > _DATA_MD.txt
rem %CYGWIN_BIN%\cat _DATA_MD.txt | %CYGWIN_BIN%\perl -ne '$_ =~ /^([0-9a-fA-F]*)/;my( $s_hash_str ) = $1;while( length($s_hash_str) > 0 ) {$s_hash_str =~ s/^(........)//;printf("0x$1\r\n");}' > _DATA_bin_for_SecureUpdate.txt
%CYGWIN_BIN%\cat _DATA_MD.txt | %CYGWIN_BIN%\perl -ne '$_ =~ /^([0-9a-fA-F]*)/;my( $s_hash_str ) = $1;while( length($s_hash_str) > 0 ) {$s_hash_str =~ s/^(........)//;my( $s_hex_8bit ) = $1;print( pack( "L", hex($s_hex_8bit) ) );}' > _DATA_bin_for_SecureUpdate.bin

AddHeader.exe 6 255 _DATA_bin_for_SecureUpdate.bin

@copy _DATA_bin_for_SecureUpdate.bin/B secure.bin
@copy wk\_DATA_bin_for_SecureUpdate.bin_addhead/B + DATA.bin/B DATAS.bin/B

del _DATA_MD.txt
rem del _DATA_bin_for_SecureUpdate.txt
del _DATA_bin_for_SecureUpdate.bin


@echo %0
@echo complete !

:EXIT
endlocal
exit /b
